/**
 * 作用：更新dist中的文件
 * 
 */
let gulp = require("gulp"); // gulp是一个实例对象;
var cleanCss = require("gulp-clean-css");//压缩scc
var babel = require("gulp-babel");  //js ES6转换
var concat = require("gulp-concat");    //文件拼接
var rename = require("gulp-rename");    //文件重命名
var uglify = require("gulp-uglify");    //js uglify 压缩
var sass = require('gulp-sass');
sass.compiler = require('node-sass');
var { paths } = require("./gulp.config"); //json文件引入
var dev = require('./gulp.dev');  //调用监听文件
let type = process.argv[3] ? process.argv[3] : "dev";
function style() {
    return gulp.src(paths.style.src)
        // .pipe(concat('index.css')
        .pipe(sass().on('error', sass.logError))
        .pipe(cleanCss('index.css'))
        // .pipe(rename({
        //     suffix: '.min'
        // }))
        .pipe(gulp.dest(paths.style.dist));
    ;
}

function javascript() {
    return gulp.src(paths.javascript.src)
        // .pipe(concat(
        //     'main.js'
        // ))
        // .pipe(babel({
        //     presets: ['@babel/env']
        // }))
        // .pipe(uglify())
        .pipe(gulp.dest(paths.javascript.dist));
}
function json() {
    return gulp.src(paths.json.src)
        // .pipe(concat(
        //     'main.js'
        // ))
        // .pipe(babel({
        //     presets: ['@babel/env']
        // }))
        // .pipe(uglify())
        .pipe(gulp.dest(paths.json.dist));
}
function modules() {
    return gulp.src(paths.modules.src)
        // .pipe(concat(
        //     'main.js'
        // ))
        // .pipe(babel({
        //     presets: ['@babel/env']
        // }))
        // .pipe(uglify())
        .pipe(gulp.dest(paths.modules.dist));
}
function html() {
    return gulp.src(paths.html.src)
        .pipe(gulp.dest(paths.html.dist));
}
function php(){
    return gulp.src(paths.php.src)
        .pipe(gulp.dest(paths.php.dist));
}
// function watch(){
//     gulp.watch(paths.html.dist,modules);
// }

var build = gulp.series(style, javascript, html, modules,php,json);

exports.build = build;
exports.dev = dev;
